fixing some uncovered scenarios

fixing some uncovered scenarios
fixing database structure