reduce 30 lines of code