refactoring. much cleaner now!