working code with all features supported and all comments