Fixed issues

Removed duplication in the sql statement builder.