Working version extended a bit.