Refactor

I started to review the code for security bugs and saw a few places where I would refactor the code. Do accept PRs for these sort of changes?