rewrote functions to work with new database