Cleaned up some code and removed a larger loop