Totally rebuilt based on [Code-Mirror]