Fixes for #6, #7, #8 and some other improvements