refactor and improve example