added writeDistance for displacement