Added a bunch of useful utility functions and test for them