Fixed function not returning correct type