fix a bug that patterns are not exaustive and make it relocatable