Refactored hardware functions to be testable.