Cleaned up code after switching to json