Refactor code to work on server. In particular database access