code cleanup, more comments added