Changed all foldRight into foldLeft and fixed some errors. Now compiles!