bug fixing + better format_url function