code refactored. producer consumer model applied.