Undo improvement

The index function inside undo has been improved to return both an integer and a bool value to indicate success. View and undo_test had to be slightly modified to reflect this change. A redundant if statement was removed, some sections of code were converted into closures and the for statement in the index function was slightly modified so as to eliminate the need for an extra line.