refactored BPM calculations into one function