finally got it to work :/ malloc-ing is annoying