Fixed bug with encoder