Added comments and error catching.