Better SQL execution and error handling.

Reworked the SQL execution logic to avoid some unnecessary loops; added error
handling; added better debug logging (use env var DEBUG=router or just npm
start).