Some code improvement. Tests are a bit better now.