Cleaning up the code and minor changes