Some fixes of potential bugs which can cause undefinded or unwanted behaviour