reworked event listener and added onReady function