Fix javascript onRemove function