added comments and demo() function