Refactored collectData

Improved collectData and refactored in changes. Now easy to read and
should be slightly faster.