Code cleanup + minor fixes

@lennartcl