Ported program from c++