Using array filter to simplify the code.

Credits for the though @pespantelis