Improve sqlite performance
Implement most of the functions model