improved code structure and dependency calculation