extensive testing and fixes