use active pattern and fix signature