More consistent code

This is just a first part of making code more readable and consistent. External API (the one visible to the end-user) shouldn't change so it's now up to us to rewrite internal API to make it as simple to read and go through as possible.

I got rid of unnecessary variable, moved some variable declarations to function scope in which they're actually used in. For more info please refer to commit messages and diffs.

More pull requests to be provided in the nearest future.