Extracting few methods to improve readability

This commit does not change any functionality. It barely extracts couple of methods to make reading easier. Also keep in mind that shorter methods are more likely to be optimized, inlined, etc.