reworked some code