Fix comments
Use $functions to check if functions exits
Merge in upstream changes