Cleaned code, added comments describing each function