Did some cleanup and added comments