rewrite using a cleaner approach with same efficiency

closes #12
Release 1.2.0