Split it to testable functions.