Merged some code from MOST