make the moving logic generic so it works for columns and rows in either direction