finished initial untested implementation