Update script with comments and out of bounds fix