restructure code for readability