God is the moral code, and we can be led by the Holy Spirit which would guide us AWAY from sin so we can be perfect in the eyes of The Creator, which is given to those who accept Jesus Christ as there personal Lord and Savior (there for stating that you will live under God's moral code to the best of your ability), and even though you are given the Holy Spirit, you will still make mistakes occasionally and sin, and if that happens, you would ask God for forgiveness, and turn away from that sin. "The closer we come to perfection, the less punishment we get for not being pure in our ability to abide by this moral code? " Well the answer is yes and no again as all wrong has it's punishment by humankind, (e.g. murder can have the capital punishment sentence, stealing has a punishment etc.) but God has punishment of some sin through humankind as well, but then he directly punishes Human's for sin as well, but in answer to your question, no, us as Humans as selfish as we are we can't get close to perfection "the closer we come to perfection....", that's why we accept The Creator which is God, his gift of grace on the cross so that our sins can be forgiven and we turn away from ALL our sins, which we do through the Holy Spirit which leads and guides us to do so. "Does this god create the punishment, or is this also an inherent part of this moral code which exist outside of his control and abilities to control?" Yes, God creates the punishment, and yes it's a inherent part of God's moral code that is the only moral code which is Right or Wrong, and no, God doesn't need to control a moral code, because he IS THE moral code, because if there was no punishment for sin there would be no reason not to, but God gives us the choice to sin, or to not, but that punishment is Hell, you see because when we die, we don't really die the Bible says, "For the wages of sin is death...Romans 6:23" when it says that...it is talking about the gruesome, terrible, eating up of our souls by Hellfire which the Bible says was made only for The Devil and his angels, but through us not wanting to turn away from our sins God will give us sins punishment, death of our souls, not existing anymore, but forever this time and with the worst pain ever, before the ultimate death of our souls, to put us out of our misery so to speak, and God sadly having to do so, as truly, "For the wages of sin is death..." or the punishment of sin is death, and it truly is. If you want I recommend going to Bible gateway and using the EXB (Expanded) Bible to study the book of Romans. (known as the epistle of Paul to the Romans) It will help everybody's understanding I promise.