seems that it works, but the code needs cleaning