Solved problem --- cleaning up + implementing better way to take number of occurrences of tls