tested code, fixed all issues, still lacking NAs though