Refactoring the buildPanel method so it can be tested.
Some refactoring so that buildPanel can be unit-tested.