Refactoring, cleanup, minor feature updates

Syncing up some minor cleanups, code fixes into netflix:master. API remains unchanged so it should not affect applications using Pytheas framework.