Fix horrific bugs