Refactor complete. Code works and is much cleaner