Various code fixes from static analysis