Refactor server <-> resource layer. Add integration tests. Add logging