Reduce number of return branches in function