completed efficient animation algorithm