Various bug-fixes and additional changes

Committing latest changes including additional tests, minor bug-fixes,
additional functionality and changes to usage.