Refactored and added 3 functions to be reused.