Algorithm for the solution of internal variable problems in plasticity