implementation and tests