main recursive routin implemented