fix #223. Add a test to make sure the panic is fixed