Fix reference error and bad try-except. Closes #35.