Added support for automatic phase2 and added routines which return some internal parameters.