refactored code and updated JSCodegenVisitor