Cleaned up code to make more readable