Make profile rendering code a bit more robust