Refactored
Added -d option
Added simple test