Refactor and fix hydration