Updated code, now it works