broken into db and logic and added unit tests