Merged with Wei's changes