Refactoring based on review comments from Patrik Nordwall