[Hazi] Refactored code
[Hazi] Final version before robustness testing