Added some comments, braces, and another !empty check.