reverted to fix memory allocation bugs, and fixed incorrect bitmask output