extract 'control' from modal
add move environment-related code to an 'environments' module