Portable tests

and minor code cleanup