Cleaned up the code. Updated comments