extract base code into lib/utils/