Removing old layout reference when changing layout 

Avoid errors when handling the layoutchange event (fixes #118)