Revert "Revert "Bug fixing""

This reverts commit a02b6f73d908ecbb7e4d6aa9696d3bfbce286f23.