Updated animatef function