Code works with animation running seperately