A Twisted Flux Rope Model for Coronal Mass Ejections and Two-Ribbon Flares