Rewrite cow movement algorithm