Refactoring to make more flexible