Updated the functionality to be more flexible