Bug Fixes.

Fixes for #97, #87 and other minor fixes.