Code cleanups, more explanative comments added