refactored parsing to iterate throught the parsed html doc with only once instead of n times