implement findAndModify function