Bugfixes and little cleanup.