Second cleaning of code. Some bugs appeared as consequence.