simplyfy recursive solution