fix memory size arithmetic