better error logging; add limit to main