fixes, add selftest