Code cleanup / minor bugfixes