optimization partially debugged