Added tests and db accesss (still not working properly)