the main program

debugged version...not yet tested