Added everything into the ready event for the document to prevent
premature crashes