fixed almost all testing, added functions for db