Refactored some of the code to be better managed.