more advanced db-based version