added history API, still buggy. Working on refactoring next as code is getting a bit out of hand. (tiny bit of refactoring in this commit, sorry)