Cleaned code and added comments