refactoring for cleaner code