Extracted some functionality into separate classes.