refactored bit flip functionality to make it more generic