Added bounds checking
Fixed a severe, but tiny bug
Added default return values
Added function prototypes