A clean up for the code and added comments