Why are you using base58 encode, rmd160 checksum? You don't need any of them, just input rmd160 as your targets and stop the process at rmd160, once you generate the rmd160 don't do anything else with it other than comparing them with targets. Remember, from rmd160 to address there are 2 sha256 hashing and 1 base58 encoding, both are heavy. Get rid of them.