Revised code structure. Ready for XML processing