Added base code written by Bo Yang