Fixed warnings for the lolz (+ some logic errors)