cleaned a lot the code