Fixed up hanging logic
Adding back encoding for now