refactoring minor bug fixes