Bunch of small fixes. Starting rewrite.