cleaned a bit the code