Some re-arranging for new version. Added flags.