Fix a defence range bug, add some doc comments and refactor