Added mode chaning button and rewrote code to accomodate it