Pretty much works

Just need to work out a few bugs in it