Some slight stylistic changes made in order to avoid exceeding cyclomatic complexity requirements for Checkstyle.