this is finally doing it correctly, somehow... gonna clean up the code and continue