code enhancement after suggestions from Jason (codereview.se)