tweaking up and down movement and adding pattern search