fixed minor but serious flaw in defined function