Finished program with 4x4 and 6x6 modes