clean-room reimplementation