Fix various code smells