refactoring to improve performance