Started work on sql functions