Really ugly river code that WORKS (99%)