New functions and cleaning up