move modal logic to layout