moved functionality to seperate function