Various bugfixes and feature additions