working version of part I and II