refactor js callbacks