Some fixes and global funcition __