Everything works (at least it should)

But code is probably very nasty. It will definitely need some cleanup.