Modified code to be reusable for whitelist and blacklist