add working code and comments