refactoring the code and implementing the DAO layer.