Replace argv parsing with argparse, added if __name__ == __main__ block and main() function, added doctests