refactoring for much cleaner code