New functions and speed improvement