trim tests and fix various bugs