Lots of bugfixes and feature additions