Works again, however code still messy