Use angular.isUndefined and other minor cleanup