Fixing some bugs that came up when testing