refactor and make more dynamic