Start putting queries in try blocks, other fixes