Cosmits, minor bug fixes and improved example.

Changes implemented in #46 included here along with other cosmits. Thanks @dongqunxi . 

Added more functions to the example test script. Please make sure to run the test script using the test data after / before making any changes.