code cleanups, added a few comments