Cleaned up logic. Made code readable.

Hello,

The code I've posted is much more understandable to developers. Please consider using it.

Thank you,

Erwan Lent