Fix stack corruption, fix memory issue on write queue