Much cleaner database querying/json forming