Fix behavior inconsistency and add test