fixing comments and code reorganization