fix many functions, make it more tolerant to none persp, lot of bugfixes