Need to rewrite encode