incorporating Nick A's suggestion after code review