first working version (need to add migration and fault tolerance)