final improvement to problem #3