Working version

Working version with Carma's change.