started encoder support and simplified code a little bit