refactoring for better flexibility