Major improvements to SQL relationship and statements fixes #2