refactoring to make it simpler