Refactored code. Now much cleaner.