integrating Robbie's code.