Fixes for #9, #11 and some other improvements