Restructured and add jQuery functions