Fixing formatting of code and refactoring some performance related
aspects.