Messy but tests are passing