implemented append using foldRight