First commit; helper functions and tests mostly implemented and under test