Replaced a couple of repmat calls by bsxfun calls.