First working version with DB support