Cleaned up code, and refactored some code in some methods.