small refactoring bug fixes