Made it a bit more robust