changed from doc ready to function