Bugfixes and formatting. Have not yet tested.