refac and add first version of encoding