Separated code into distinct functions