implemented codes for theory II