bug fix. code refactoring