Some optimizations and code tidy up
Fix bugs handling path brush images and add a minor optimization