made code more clean, 30 lines