added history and undo option; bug fixes