Cleaned up code to make easier to read