Refactor format_paths; Thanks to @knewter for pointing out