improved log performance
updated code style
refactored recursive state change method to iterative method