fixes a bug that Jarid found and adds a test so it won't happen again