add a whitelist, refactor and cleanup