Performance fixes and small tidies