a bit of code refactoring