Added comments, some light error handling, and renaming