version adapted from neil