Beautified code and added comments