Implements bubble positioning logic.