Pre-structured, messy, but all functions tested and working