tests reorganized, bug fixes