More code optimizations

I am adding this pull request so that you will know of my current work.
I might add some more changes in the weekend but I wanted to get this visible to you as soon as possible in order to not work on the same things.

This pull request will continue the work I've done in the previous pull request, this time taking care of little things like caching of frequently used values, jQuery chaining but also cleanup of some unused variables and marking of todos.

EDIT:
This pull request is now ready for approval testing