fixes to select statement and connection