Bunch of bugfixes and minor expansions code-wise.