added method function
added while loop