Fixed bug in SQLProvider.
Cleaned up code and added some additional functions.