minor opti. refactor needed