Working on referencing variables in nested javascript functions