Improving/fixing some logic