Hacked together to work :D