added basic tests and fixes - most things yet untested