Restructured for better code readability