Code refactoring and added new functions