Refactored a bit into modules.