Robert's bpm function, refactored by Robert