First working version, still a few rough edges to smooth and the loop functions to integrate.