Fixinq sql issue. resolves #1