Cleaning up the code, half way done.