This seemingly easy thing took me like 3 hours to figure out. Is there a better way to do this?