added psuedo code