fix segfaults by endless loops

added checks if the called methods exists
unfortunately with trimmig trailling spaces