Implementation of functions and testcases