starting encoding function