minor changes and code refactoring