Replace simple SERVE_LOCAL mechanism with more flexible solution, also fixes bug.