New functions and bug fixes