first slightly working commit, some cleanups too.