fix exception and add test