Fixed some bugs to get it working