Added options (-r and -o)
Fixed some bugs