cleanup, fixes and tests