working version based on sequences