updated encoding method