Code refactoring for the bubble tutorial