diff --git a/pymolfile/pymolfile.py b/pymolfile/pymolfile.py
index a4cf702e0011ca256bdd2142841e00b744fccd59..7396a238d9ea3f77bbabd5c6f877520fa28bb399 100644
--- a/pymolfile/pymolfile.py
+++ b/pymolfile/pymolfile.py
@@ -521,17 +521,18 @@ class OpenMolfile(object):
                     if self.topology:
                         num_atoms = self.topology.natoms
                     elif self.kwords["natoms"] is not None:
-                        num_atoms = natoms
+                        num_atoms = int(self.kwords["natoms"])
                     # Trajectory can be read if num_atoms is set
                     if num_atoms>0:
-                        self.trajectory = Trajectory(file_name,
+                        self.trajectory = Trajectory(
+                                self.kwords["file_name"],
                                 self.kwords["file_format"],
                                 self.fplugin,
                                 num_atoms,
                                 self.kwords["silent"])
             else:
                 warnings.warn("Pymolfile can not find a plugin to open the '" + self.kwords["file_format"] + 
-                      "' file format of the file " + self.kwords["file_name"] 
+                      "' file format of the file " + self.kwords["file_name"]) 
 
     def initialize_settings(self):
         #global MOLFILE_PLUGINS