Refactored to add layers and abstractions.