Refacor toward event-based structure and new code layout.