Event handling

Another try on #211