code cleanup, comments added