Clean up SQL syntax; add methods for querying and deleting chains