final refactor with minor changes