reworked the logic, rewrote part of the api