start refactor in new file
smaller functions, hopefully more readable