some optimization, works a lot faster now