improved code structure