I would check the vanos solenoids. See this DIY for more info:
He is physically replacing the solenoid but all you need to do it pull them out, clean them with some MAF cleaner and then hit them with some compressed air. I would switch the exhaust and the intake also to help extend the life of them. They commonly get clogged which can give you the symptoms you see above.