fixes fatal error and adds test to catch it next time