Reworked code until it passed basic tests