move out xml code; important bug fixing