Code improvements

Incorporating feedback received while reviewing the first iteration.
API improvements and code simplification.