Full rewrote and now it works