improved checks for nullptr
using shared ptr
for each loop
using reference
using const reference