2014-01-03 Massive refactoring, new functions, all tested