Fix, based on Marc Brooks solution