refactoring to make it cleaner