Refactoring to simplify possible changes.
Added validations for the indices.
Implememnted stats, as described in the course.