finished FindPattern function