added the last case, and made the -o flag work