Restructure code to separate implementation from tests