Corrected tests to conform to spec
Internal reorganisation of utility functions