adding async behaviour to conditional logic

This improves the JS performance drastically resolve #287