Refactored, added -d and --help options