Fixes insert function. Adds return of exception as return value for query statements. Adds static functions where necessary