Adding decode and encode functions