Fix for #9422

After som help from @Pvince81 I managed to fix the bug in #9422 

Please review.