Big cleanup + small bugfix

Closes #180