Static code fixes + a resource leak fix, feel free to reject if mainly not useful.