Encapsulated function and added new functions