remove string typecast and correct counter conditionals