sql issues sorted out, merging with dev branch