Cleaned up some code and fixed a bug in XMLFactory