Working version with Eric's suggestions