tests, fixes, refactor