added encodeDirect