Added Sophie's code for encoders.