Fixed bug with ready event not triggering at the right times in some cases