complete rewrite unfinished commit #2
complete rewrite unfinished commit #3