moved number assignment in one method
implemented stateChanged event