Some bug fixes for #2