implemented some methods using foldRight