Add state checking and more verbose logs