cleaned up, reworked