Fix some code style; add a test for #407