database schema and some code organization