Cleaning up the code and fixing some typos.