Random fixes, slightly better bounds checking.