Revert "patches to corrects bugs"

This reverts commit d525d62daa7080d837dee2c580b03aeec7eb2e0e.

This must go through a pull request for review.