Minor performance improvements in the code