made huge refactoring, implemented history fetching