Fixes for #61 also fixes #47, with tests to prove so