SQLite Database saving code reworked

This closes #001