Altered implementation and tests