encode position at once