improved code structure and layout