Refactor for backward compatibility, add test