refactor and improve docs