refactor receiving javascript