backend api: Pass context to close function, cleanup