fix implementation and tests