added optparse and fixed input