Also cleans up the encoder a lot, removing some complicated logic introduced by the initial round of implementation