major refactoring - still some to do (tags database).