Some code cleanup and comments added