fix resource handling, fix sql handling