rearrage code to ease testing
server queue tests and fixes
refactor database and add tests