working revamped version, created in a sprint. full rewrite with atomic commits to follow