Add a unit test + Some improvements