move special wan code into own function and make it more robust