updated comments, minor fixes and refactorings