refactored connections
moved sql statements, check for duplicate long urls before creating a new one