adjusted encoding, added label counter