Fixing function variable mismash, adding tests