Added some bounds checking, fixed some minor array hiccups, a classic failure to update a #define, and added static appropriately