Added pointer cleanup for state machine