replaced try/except with correct contraints