refactor the code structure for sanity