Moved some logic to separate methods.