added context parameter and fixed a bug