Updated the dispatcher to be more effecient

Made the dispatch function use a queue to hold functions and checks
for more effecient queing functionliy for the javascript engine