Updated language detection on both the frontend and the server to reduce failures due to empty blocks and whitespace.