WIP: more cleanup and fixes, initial support for delegation