Extract code and test utility function