Working after putting all code in functions