Refactored: used simplified approach to calling JS functions when default context is OK