this code was getting too messy and scattered, and I realized that Flask wasn't doing as much as I thought it was here, so now we need more safety and sanity checks