Reworked how buttons determine their position and fixed the layering issue