Updated code per Alex's suggestions.