refactor code, added ability to stop loading data