simplifying code using @ronwsmith suggestion