complete rewrite unfinished commit #1