complete rewrite unfinished commit #4