Refactored some sloppy code to conform to standards