Fix a few issues detected by static analysis

I used Linter and a few custom regexes to find these issues.
Nothing serious, but the code is a bit cleaner and faster.