Added Robert's code. Changed controller variables to class variables.