combined two implementations of CoordinateEncode into one