stable working version. refine dates & queries time permitting