Rewritten db.class, templates added.