Cleaned up some code for readability and maintainability