Fixed some logic