add sqlite singleton instead of passing resource around

plus other tidy up