Static code analysis and code style cleanup

This goes through and applies code analysis suggestions from IntelliJ and fixes the code style to be in line with runsafe standards.