code modified with own functions