Moved a function to more logical place