Refactored to plain functions.