Cleaned up and organized some code