messy first implementation of balance