Fix for bug @halvors reported. Nice catch