Some fixes for errors in last pull request and some more issues

* Fixes for #25, #29, #30, #31, #32