hacked the code a bit to make it work