fixed. code moved into generate_url