Added a DAO class for all DB operations
some logic fixes