reworked from scratch