fixing out of range bugs and errors. Thanks for the help Kazu!