Clean up, rename and comment all the code (well some of it at least)