Use document.onready and wrap JS in closure