pin handler added
fixed errors
states may not work properly