regoranize code and implement basic history