maybe abstract this logic and move it to a case instead of using next