Various small fixes found through static analysis