These two methods are doing very similar things, maybe the logic can be extracted?