huge bugfixes and changes