unit tests and updates to address reentrance issues