added pattern logic

this is incomplete and not working properly