fixed examples so that they do not contain compile errors
added safety check