complete rewrite from first commit