Refactored into functions.