debugged this in repl instead of just throwing shit on the wall and hoping it works like the last version of this function