Merged with zhan's changes