Various refactorings. Reduced visibility of many elements and added final where possible.