Improved output formatting; added improved out-of-bounds checking