Changed handling of connection field, better cleanup of database
connections.

Signed-off-by: Nigel <Nigel@192.168.38.1>