New functions and bug fix