Optimize some logic.