refactoring for better performance