restructure code to be shorter