Refactored and added support for handling -o and --output command line options.
Added checks for proper handling -o and --output command line options.