Separated the long functions into different functions