finshed logic with functions