Implement avoidance

Not perfect, need to make it work later.