functional version with new workflow!