Code clean-up, plus some minor fixes based on some negative tests