fixed minor syntax errors and nil sanity checks