Move some static strings to constants and remove some duplicate code