added history handling.
history seems to be working now. fixed many-many bugs.