added a bunch of stuff to make it work