Fix bug leading to space overflow error