Fixes for #4, #6, #7, #8