some fixes, more rewrites