seperate functions and move all js into external script