Updated code from demo