couple bugfixes and cleanup