Added getopt, made sandr class, fixed many bugs