logic added for ontrack/offtrack calculation