Code refactor for global variables and for-in loops

A lot of global variables are being used in lib.js
All for-in loops where iteration is being done on array has been converted to
forEach loop. This further reduces global variables.
constructorReturnCode is the new variable name for return codes from larry
constructor. This is being used in core.js. Hence a change has been done there
as well.