Performance improvements

We had a project, where I used this plugin with tons of options (>4000). It was slow, so I had to make some improvements. It is still not super fast, but faster than before.  
Changes to code are self-explanatory, but if needed, I can write comments.