Total package refactor

Plus unit tests