Updated to use SQLlite rather than arrays