Code clean up and comments added