Fix some issues found by code inspector