fixing up some bugs to make it work properly