move algorithm