My code may not seem clean but after all it works and gives good results while debugging. Anyone could verify what's wrong? Maybe I'm blind for some mistake.