cleaned up some code, removed/improved few comments, better logging