Refactor functional units, add tests for all functions.