Very unbalanced, but it works. Removing debug messages.