fixing some bugs that affected #20, still investigating