Added in additional tests; tidied up implementation