refactor and make it process more stored variables