Commented and improved the code by removing thread blocking code