Pim refactor

First bunch of re-factoring

closes #8 closes #3