factoring out all code related to SQL Functions