clean up if statements and tidy up tests