implemented take using tailrec.