Modify and finalize the functions with tests