Small performance improvements

Hi I've made some small performance improvements, please have a look
(recreated request, was missing a commit that fixed a small issue)