Added SQL Database support. Cleaned up code.