@drsnyder code flow fix
@drsnyder replaced type casting with empty()
@drsnyder - simplifications
refined unit tests