Fixed test and tidying code