implement functions without using recursive method