solved, but slow and dirty code
twice faster than previous
refactored, but yet quite dirty