reworked to be more efficient