major changes, added database functionality

still many debugging lines (web alerts), many commented out, some still present.
Need to fix isAtomic. Currently it's a boolean in this file, but in the database, the variable is "type", and takes string values "atomic" or "duration"