Restructure to be more easily testable