Moved some functions out to helper class.