Changed program into function