bug fixes for the code refactoring