Try moving encode definition?