Include global $link in every function generated.
Also fixed indentation