first working version with unique states