Encoder code for midterm demo.
Saved on midterm day