Fixed invalid buffer, and added command line options