fixed implementation of database