Main.r

first functional version, requires careful validation