Support for refs
Add a simple version
Better state management