Implementation of support functions and tests