Added state clearing and initialization in the constructor