Extract common methods and add tests for them.