Separated the function in two functions