first working version. too many fixes and changes to mention.
added first command line options.