Lots of changes, bugfixes