moved db connect to top level, better error parsing on client