added comments and prettified