Fixed minor bug which was preventing the encoding from working. Refactored the encoding methods