Added -max command line switch, fixed command line bugs