Added onready function to wrap the rest of the stuff to try to minimise loading issues.