Moved code into some classes.