Fix Fundbugs-detected bugs