Final code fully functional -- passed all example tests