revert to less pretty implementation that works