Bunch of improvements/bugfixes.