fixed the fatal exception caused by the last change; code cleanup