complex but seems to work great now!