Bugfixes and removal of vestigial code. Last commit was buggy.