Improved data structures. Some refactoring.