Add detailed test for #316 and fix it; fix to be discussed though.