Refactored some code, cleaned up syntax.