refactor code based on documentation