Refactored disconnect handling, updated engine