finished reimplementation