Syntax fix and bug fix for undefined value

Add missing semi-colon.
Move vars to top of function.
Assign '' to pair.from if it is undefined.