De-spaghettify frontend code