added transitions
fixed timing bug by using recursive call to setTimeout