Cleaned up slightly. Have noticed there is a bug with the history if you are too quick.