This is some code written by Ning Wang