Code cleanup and comments added