renamed db to database to fit coding guidelines
replaced direct access to superglobal with wrapper
simplified code, no duplication anymore