reworked all code