general cleanup and enhancement of tests and functions