total reimplementation, added feautures