There's a way easier way to do that.

- - - Updated - - -

Plus your code is filled with logical errors.