Added selected text to the contextual menu, and fixed a bug in frame handlers