Fixes for #28, #42, #44, #45, #46, #47, #49