improve move algorithm