Added some DB code, to store data more efficiently.