Refactored most of the names, also added comments in most of the files, and fixed identation. Added error handling