web: remove some repeated code