minor bug fixes and refactorings from master branch