Big set of changes from TJ Repo.

been sitting on my local for ages! :(

-couple of bug fixes
-minor refactorings
-package updates