code refactoring a little bit