more eficent/readable recursive code