maybe we should refactor this method and split it up to make things more readable