Cleaned code and added comments, currently broken