Fix returns and handling of JS callbacks