Specific Code and algorithms:

(See this for philosophy and generalities.)