entity to element serialisation and general refactoring