Copied necessary code from StandAlone.