bwa refactoring