rewrote again. try fixed the main bug