Modified to remove echo's from functions and replace with return