Improved Chris' script