Moved duplicate code to methods